﻿Imports MeoTom.Core.BLL
Imports System.IO
Imports Microsoft.ApplicationBlocks.Data

Namespace DAL
    Public Class PageProvider
        Inherits DataAccess
        Private util As New Utilities.Common()

        Public Sub New()

        End Sub

        Public Sub Create(ByVal a As Pages)
            Dim param(11) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
            param(0).Value = a.PageID
            param(1) = New SqlClient.SqlParameter("@PageTitle", SqlDbType.NVarChar, 550)
            param(1).Value = a.PageTitle
            param(2) = New SqlClient.SqlParameter("@PageTitleNone", SqlDbType.VarChar, 550)
            param(2).Value = a.PageTitleNone
            param(3) = New SqlClient.SqlParameter("@Status", SqlDbType.Int, 4)
            param(3).Value = util.ConvertBoolToInt(a.Status)
            param(4) = New SqlClient.SqlParameter("@CommentsEnabled", SqlDbType.Int, 4)
            param(4).Value = util.ConvertBoolToInt(a.CommentsEnabled)
            param(5) = New SqlClient.SqlParameter("@ReleaseDate", SqlDbType.DateTime)
            param(5).Value = a.ReleaseDate
            param(6) = New SqlClient.SqlParameter("@PagePath", SqlDbType.NVarChar, 600)
            param(6).Value = a.PagePath
            param(7) = New SqlClient.SqlParameter("@PostBy", SqlDbType.Int, 4)
            param(7).Value = a.PostBy
            param(8) = New SqlClient.SqlParameter("@PostVisible", SqlDbType.Int, 4)
            param(8).Value = a.PostVisible
            param(9) = New SqlClient.SqlParameter("@PagePassword", SqlDbType.VarChar, 150)
            param(9).Value = a.PagePassword
            param(10) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(10).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Pages_Create", param)
        End Sub

        Public Sub Update(ByVal a As Pages)
            Dim param(8) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@PageTitle", SqlDbType.NVarChar, 550)
            param(0).Value = a.PageTitle
            param(1) = New SqlClient.SqlParameter("@Status", SqlDbType.Int, 4)
            param(1).Value = util.ConvertBoolToInt(a.Status)
            param(2) = New SqlClient.SqlParameter("@CommentsEnabled", SqlDbType.Int, 4)
            param(2).Value = util.ConvertBoolToInt(a.CommentsEnabled)
            param(3) = New SqlClient.SqlParameter("@ReleaseDate", SqlDbType.DateTime)
            param(3).Value = a.ReleaseDate
            param(4) = New SqlClient.SqlParameter("@PostVisible", SqlDbType.Int, 4)
            param(4).Value = a.PostVisible
            param(5) = New SqlClient.SqlParameter("@PagePassword", SqlDbType.VarChar, 150)
            param(5).Value = a.PagePassword
            param(6) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
            param(6).Value = a.PageID
            param(7) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(7).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Pages_Update", param)
        End Sub

        Public Sub Delete(ByVal a As Pages)
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
            param(0).Value = a.PageID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Pages_Delete", param)
        End Sub

        Public Sub UpdateArticlePath(ByVal a As Pages)
            Dim param(3) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@PagePath", SqlDbType.NVarChar, 600)
            param(0).Value = a.PagePath
            param(1) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
            param(1).Value = a.PageID
            param(2) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(2).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Pages_UpdatePath", param)
        End Sub

        Public Function GetAll() As DataSet
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(0).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_Pages_GetAll", param)
        End Function

        Public Function GetByEdit(ByVal a As Pages) As SqlClient.SqlDataReader
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
            param(0).Value = a.PageID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Pages_GetByEdit", param)
        End Function

        Public Function GetAfterIns(ByVal a As Pages) As SqlClient.SqlDataReader
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
            param(0).Value = a.PageID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Pages_GetByEdit")
        End Function

        Public Sub UpdateViewCount(ByVal a As Pages)
            Try
                Dim param(2) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
                param(0).Value = a.PageID
                param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
                param(1).Value = Configs.SiteID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Pages_UpdateCount", param)
            Catch ex As Exception
            End Try
        End Sub

        Public Function GetTop10Last() As SqlClient.SqlDataReader
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(0).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Pages_GetTop10Last", param)
        End Function
    End Class
End Namespace
